package com.usian.admin.controller.v1;

import com.usian.admin.service.AdChannelService;
import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.common.exception.CatchCustomException;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.admin.pojos.AdUser;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.user.threadlocal.AdminThreadLocalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@SuppressWarnings("All")
@RequestMapping("/api/v1/channel")
public class AdChannelController implements AdChannelControllerApi {
    @Autowired
    private AdChannelService adChannelService;

    /**
     *
     * @param channelDto
     * @return
     */
    @Override
    @PostMapping("/list")//传值的话使用post
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto channelDto){
        AdUser adUser=AdminThreadLocalUtils.getUser();
        if (adUser==null){
            CatchCustomException.catchs(20002,"用户不合法，没有登录");
        }
        //获取dto参数 1、url方式传值  2、表单方式queryparam（同步）  3、json方式
        return adChannelService.findByNameAndPage(channelDto);
    }

    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel adChannel) {
        return adChannelService.save(adChannel);
    }

    /**
     * 根据id返回数据
     * @param id
     * @return
     */
    @Override
    @GetMapping("/{id}")
    public ResponseResult findById(@PathVariable Integer id) {
        return adChannelService.findById(id);
    }

    /**
     * 根据id修改数据
     * @param id
     * @return
     */
    @Override
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }
    /**
     * 根据id删除数据
     * @param id
     * @return
     */
    @Override
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return adChannelService.delete(id);
    }
    /**
     * 根据id批量删除
     * @param id
     * @return
     */
    @Override
    @DeleteMapping("/deletes")
    public ResponseResult deletes(@RequestBody Integer[] ids) {
        return adChannelService.deletes(ids);
    }

    /**
     * 查询全部
     * @return
     */
    @Override
    @GetMapping("/channels")
    public ResponseResult findAll() {
        return adChannelService.findAll();
    }


}
